<template>
  <div class="fenpei">
    <div class="fenpeis">
      <el-button type="primary" @click="fanhui"> 返回 </el-button>
      <el-button type="primary" @click="fenpei"> 删除 </el-button>
      <!-- <div>
        <el-select
          v-model="type_id"
          placeholder="请选择类型"
          @change="user_review_list"
        >
          <el-option
            v-for="item in options"
            :key="item.id"
            :label="item.com_type"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </div>
      <div>
        <el-select
          v-model="com_id"
          placeholder="请选择企业"
          @change="user_review_list"
        >
          <el-option
            v-for="item in option"
            :key="item.id"
            :label="item.com_name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </div>
      <div>
        <el-select
          v-model="award_id"
          placeholder="请选择奖项"
          @change="user_review_lists"
        >
          <el-option
            v-for="item in options1"
            :key="item.id"
            :label="item.award_name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </div>
      <div v-if="award_id == 7">
        <el-select
          v-model="fz_id"
          placeholder="请选择分组"
          @change="user_review_list"
        >
          <el-option
            v-for="item in fz"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select> -->
      <!-- </div> -->
      <div>
        <el-button type="primary" @click="daochus">
          导出
          <i class="el-icon-plus el-icon--right"></i>
        </el-button>
      </div>
    </div>
    <div class="tables">
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        :height="tableHeight"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="index" label="序号">
          <template scope="scope">
            <span>{{ (page - 1) * 15 + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column type="selection"> </el-table-column>
        <el-table-column prop="split_id" label="申报id" width="60">
        </el-table-column>
        <el-table-column prop="data.award_name" label="类别"> </el-table-column>
        <el-table-column prop="data.type_name" label="类型"> </el-table-column>
        <el-table-column prop="data.project_name" label="名称" width="400px">
        </el-table-column>
        <el-table-column prop="data.zf_name" label="分组"> </el-table-column>

        <el-table-column
          prop="data.user_name"
          label="申请人"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column label="得分" show-overflow-tooltip>
          <template slot-scope="scope">
            <div @click="defen(scope.row)">
              {{ scope.row.score }}
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="fenye">
      <el-pagination
        layout="prev, pager, next"
        :total="num_page"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </div>

    <el-dialog
      title="评分"
      :visible.sync="centerDialogVisibles"
      width="1400px"
      center
    >
      <div v-if="obj_id == 1"></div>
      <div v-else-if="obj_id == 2">
        <innovation2 :objs="objs" v-if="centerDialogVisibles"></innovation2>
      </div>
      <div v-else-if="obj_id == 3">
        <present2 :objs="objs" v-if="centerDialogVisibles"></present2>
      </div>
      <div v-else-if="obj_id == 4">
        <Promotion2 :objs="objs" v-if="centerDialogVisibles"></Promotion2>
      </div>
      <div v-else-if="obj_id == 5">
        <Promotions2 :objs="objs" v-if="centerDialogVisibles"></Promotions2>
      </div>
      <div v-else-if="obj_id == 6">
        <craftsman2 :objs="objs" v-if="centerDialogVisibles"></craftsman2>
      </div>
      <div v-else-if="obj_id == 7">
        <achievement2 :objs="objs" v-if="centerDialogVisibles"></achievement2>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisibles = false">取 消</el-button>
        <el-button type="primary" @click="centerDialogVisibles = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import innovation1 from "../components/innovation1.vue";
import present1 from "../components/present1.vue";
import Promotion1 from "../components/Promotion1.vue";
import Promotions1 from "../components/Promotions1.vue";
import craftsman1 from "../components/craftsman1.vue";
import achievement1 from "../components/achievement1.vue";
import innovation2 from "../components/innovation2.vue";
import present2 from "../components/present2.vue";
import Promotion2 from "../components/Promotion2.vue";
import Promotions2 from "../components/Promotions2.vue";
import craftsman2 from "../components/craftsman2.vue";
import achievement2 from "../components/achievement2.vue";
import {
  user_review_list,
  review_user_del,
  typeApi,
  user_select,
  award_find,
  fz_select,
  user_child_details,
} from "../axios/api";
export default {
  data() {
    return {
      centerDialogVisibles: false,
      award_id: "",
      num_page: 0,
      com_id: "",
      id: this.$route.query.id,
      page: 1,
      type_id: "",
      fz_id: "",
      fz: [],
      tableData: [],
      tableDatas: [],
      multipleSelection: [],
      options: [],
      option: [],
      options1: [],
      objs: {},
      obj_id: "",
      tableHeight: "400px",
    };
  },
  created() {
    this.user_review_list();
    this.typeApi();
    this.user_select();
    this.award_find();
    this.fz_select();
  },
  components: {
    innovation1,
    present1,
    Promotion1,
    Promotions1,
    craftsman1,
    achievement1,

    innovation2,
    present2,
    Promotion2,
    Promotions2,
    craftsman2,
    achievement2,
  },
  mounted() {
    this.$nextTick(() => {
      this.setTableHeight();
      // 监听窗口大小变化
      window.onresize = () => {
        this.setTableHeight();
      };
    });
  },
  methods: {
    daochus() {
      window.location.href =
        "http://" +
        window.location.host +
        "/common/review_award_export?token=" +
        sessionStorage.getItem("Token1") +
        "&com_id=" +
        this.com_id +
        "&type_id=" +
        this.type_id +
        "&award_id=" +
        this.award_id +
        "&is_review=1&review_id=" +
        localStorage.getItem("ids") +
        "&fz_id=" +
        this.fz_id +
        "";
    },
    setTableHeight() {
      this.tableHeight =
        window.innerHeight - this.$refs.multipleTable.$el.offsetTop - 45;
      console.log("this.tableHeight");
      console.log(this.tableHeight);
    },
    user_review_lists() {
      this.fz_id = "";
      this.user_review_list();
    },
    fz_select() {
      fz_select().then((res) => {
        this.fz = res.data.data;
      });
    },
    award_find() {
      award_find().then((res) => {
        this.options1 = res.data.data;
      });
    },
    user_select() {
      user_select().then((res) => {
        this.option = res.data.data;
      });
    },
    typeApi() {
      typeApi().then((res) => {
        console.log(res);
        this.options = res.data.data;
        console.log(this.options);
      });
    },

    defen(e, index) {
      console.log(e);
      sessionStorage.setItem("Sanme", e.review_name);
      let params = {
        id: e.data.id,
        token: sessionStorage.getItem("Token1"),
      };
      user_child_details(params).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.obj_id = res.data.data.award_id;
          this.objs = res.data.data;

          console.log(e.review_data);
          this.objs.esid = e.id;
          sessionStorage.setItem("obj", JSON.stringify(this.objs));

          this.centerDialogVisibles = true;
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    user_review_list() {
      let aaa = {
        review_id: localStorage.getItem("ids"),
        page: this.page,
        com_id: this.com_id,
        type_id: this.type_id,
        award_id: this.award_id,
        fz_id: this.fz_id,
        token: sessionStorage.getItem("Token1"),
      };
      user_review_list(aaa).then((res) => {
        console.log(res);
        this.tableData = res.data.data.data;
        this.num_page = res.data.data.total;
      });
    },
    fanhui() {
      this.$router.push({ path: "/chuangjian" });
    },
    handleCurrentChange(val) {
      this.page = val;
      this.user_review_list();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    fenpei() {
      let arr = [];
      if (this.multipleSelection) {
        this.multipleSelection.forEach((item) => {
          arr.push(item.id);
        });
      }
      let aaa = {
        user_id: arr,
        review_id: localStorage.getItem("ids"),
        token: sessionStorage.getItem("Token1"),
      };
      review_user_del(aaa).then((res) => {
        if (res.data.code == 200) {
          this.$message({
            message: "删除成功",
            type: "success",
          });

          this.user_review_list();
        } else {
          this.$message({
            message: res.data.msg,
          });
        }
      });
    },
  },
};
</script>

<style scoped>
.fenpei {
  width: 100%;
  height: 100%;
  background-color: #fff;
}
.fenpeis {
  box-sizing: border-box;
  padding: 20px;
  display: flex;
  align-items: center;
}
.fenpeis > div {
  margin: 0 10px;
}
.tables {
  width: 90%;
  /* height: 80%; */
  margin: 0 auto;
  /* overflow: scroll; */
}
.fenye {
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>